package com.liang.design;

import com.liang.design.cook.impl.GuangDongCook;
import com.liang.design.cook.impl.JiangSuCook;
import com.liang.design.cook.impl.ShanDongCook;
import com.liang.design.cook.impl.SiChuanCook;
import com.liang.design.cuisine.ICuisine;
import com.liang.design.cuisine.impl.GuangDoneCuisine;
import com.liang.design.cuisine.impl.JiangSuCuisine;
import com.liang.design.cuisine.impl.ShanDongCuisine;
import com.liang.design.cuisine.impl.SiChuanCuisine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lsm
 * @ClassName ${NAME}.java
 * @Description 命令模式
 * @createTime 2023年12月05日 19:29:00
 */
public class Main {

    private Logger logger = LoggerFactory.getLogger(Main.class);
    private List<ICuisine> cuisineList = new ArrayList<ICuisine>();

    public static void main(String[] args) {
        // 菜系 + 厨师；⼴广东（粤菜）、江苏（苏菜）、⼭山东（鲁菜）、四川（川菜）
        ICuisine guangDoneCuisine = new GuangDoneCuisine(new GuangDongCook());
        JiangSuCuisine jiangSuCuisine = new JiangSuCuisine(new JiangSuCook());
        ShanDongCuisine shanDongCuisine = new ShanDongCuisine(new ShanDongCook());
        SiChuanCuisine siChuanCuisine = new SiChuanCuisine(new SiChuanCook());
// 点单
        Main xiaoEr = new Main();
        xiaoEr.order(guangDoneCuisine);
        xiaoEr.order(jiangSuCuisine);
        xiaoEr.order(shanDongCuisine);
        xiaoEr.order(siChuanCuisine);
// 下单
        xiaoEr.placeOrder();
    }

    //点单
    public void order(ICuisine cuisine) {
        cuisineList.add(cuisine);
    }

    //下单
    public synchronized void placeOrder() {
        for (ICuisine cuisine : cuisineList) {
            cuisine.cook();
        }
        cuisineList.clear();
    }
}